package com.fyzk.activity.lottery.jc.football.newJz.data;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tyjc.lottery.R;

/**
 * Created by fanxs11 on 16/5/3.
 *
 * 数据分析
 */
public class AnalysisRecentView extends AnalysisChildView {


    public AnalysisRecentView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public AnalysisRecentView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public AnalysisRecentView(Context context) {
        this(context, null);
    }

    public void initView(){
        super.initView();
        ll.addView(getChildView(0));
        ll.addView(getChildView(1));
    }

    private View getChildView(int team) {
        View childView = LayoutInflater.from(context).inflate(R.layout.jc_analysis_child, null);
        LinearLayout child_ll = (LinearLayout) childView.findViewById(R.id.jc_analysis_child_ll);
        TextView teamName_tv = (TextView) childView.findViewById(R.id.jc_analysis_child_tv_teamname);
        TextView game_tv = (TextView) childView.findViewById(R.id.jc_analysis_child_tv_game);


        try {
            if (team == 0) { //主队近期战绩
                JCZQ_AnalyzeResponse.HomePreMatchesBean homePreMatchesBean = ScoreDetailActivity.analyzeResponse.getHomePreMatches();
                teamName_tv.setText(homePreMatchesBean.getTeam());
                game_tv.setText("近"+homePreMatchesBean.getMatches().size()+"场 "+homePreMatchesBean.getTotal3()+"胜 "+homePreMatchesBean.getTotal1()+"平 "+homePreMatchesBean.getTotal0()+"负");
                game_tv.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
                for (int i = -1; i < homePreMatchesBean.getMatches().size(); i++) {
                    child_ll.addView(getChildItemView(team, i));
                }
            } else { //客队队近期战绩
                JCZQ_AnalyzeResponse.AwayPreMatchesBean awayPreMatchesBean = ScoreDetailActivity.analyzeResponse.getAwayPreMatches();
                teamName_tv.setText(awayPreMatchesBean.getTeam());
                game_tv.setText("近"+awayPreMatchesBean.getMatches().size()+"场 "+awayPreMatchesBean.getTotal3()+"胜 "+awayPreMatchesBean.getTotal1()+"平 "+awayPreMatchesBean.getTotal0()+"负");
                game_tv.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
                for (int i = -1; i < awayPreMatchesBean.getMatches().size(); i++) {
                    child_ll.addView(getChildItemView(team, i));
                }
            }
        } catch (Exception e) {

        }


        return childView;
    }

    private View getChildItemView(int team, int i){
        View childItemView = LayoutInflater.from(context).inflate(R.layout.jc_analysis_child_item, null);

        TextView tv1 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv1);
        TextView tv2 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv2);
        TextView tv3 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv3);
        TextView tv4 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv4);
        TextView tv5 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv5);
        TextView tv6 = (TextView) childItemView.findViewById(R.id.jc_analysis_child_item_tv6);

        if (i == -1) {
            tv6.setVisibility(View.GONE);
        } else {

            if (team == 0) {
                JCZQ_AnalyzeResponse.HomePreMatchesBean.MatchesBean matchesBean = ScoreDetailActivity.analyzeResponse.getHomePreMatches().getMatches().get(i);
                tv1.setText(matchesBean.getMatchName());
                tv2.setText(matchesBean.getMatchDate());
                tv3.setText(matchesBean.getHomeTeam());
                tv4.setText(matchesBean.getFinalScore());
                tv5.setText(matchesBean.getAwayTeam());
                tv6.setVisibility(View.GONE);

                if (matchesBean.getHomeTeam().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())) {
                    tv3.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
                } else if (matchesBean.getHomeTeam().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                    tv3.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
                }
                if (matchesBean.getAwayTeam().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())) {
                    tv5.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
                } else if (matchesBean.getAwayTeam().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                    tv5.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
                }

            } else {
                JCZQ_AnalyzeResponse.AwayPreMatchesBean.MatchesBean matchesBean = ScoreDetailActivity.analyzeResponse.getAwayPreMatches().getMatches().get(i);
                tv1.setText(matchesBean.getMatchName());
                tv2.setText(matchesBean.getMatchDate());
                tv3.setText(matchesBean.getHomeTeam());
                tv4.setText(matchesBean.getFinalScore());
                tv5.setText(matchesBean.getAwayTeam());
                tv6.setVisibility(View.GONE);

                if (matchesBean.getHomeTeam().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())) {
                    tv3.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
                } else if (matchesBean.getHomeTeam().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                    tv3.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
                }
                if (matchesBean.getAwayTeam().equals(ScoreDetailActivity.matchInfoResponse.getHomeTeam())) {
                    tv5.setTextColor(context.getResources().getColor(R.color.jczq_analysis_red));
                } else if (matchesBean.getAwayTeam().equals(ScoreDetailActivity.matchInfoResponse.getAwayTeam())) {
                    tv5.setTextColor(context.getResources().getColor(R.color.jczq_analysis_blue));
                }
            }

        }

        return childItemView;
    }

    @Override
    protected void changeData() {

    }
}
